<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>工程概况</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/layui/css/layui.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/admin.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/style.css"
      media="all"
    />
  </head>
  <body>
    <div class="layui-fluid">
      <img
        src="../../layuiadmin/images/backPage.png"
        class="backPreviousPage"
      />
      <button class="layui-btn layuiadmin-btn-useradmin downLoadWord">
        下载
      </button>
      <button class="layui-btn layuiadmin-btn-useradmin deleteTechnical">
        删除
      </button>
      <button class="layui-btn layuiadmin-btn-useradmin backNextBtn">
        退回
      </button>
      <div class="time_axis">
        <div class="time_box">
          <div class="time_box_list">
            <ul class="time_horizontal"></ul>
          </div>
        </div>
      </div>
      <iframe id="pdf" width="100%" height="800px"></iframe>
      <div class="seePdfBox"></div>
    </div>
    <script type="text/html" id="speProSchemeReturn">
      <form class="layui-form">
        <div class="layui-form-item">
          <textarea placeholder="" class="layui-textarea" id="commentsTxt">
专项保护方案内容有误，请修改后重新提交。</textarea
          >
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">审核人:</label>
            <div class="layui-input-inline">
              <input
                id="specialAuditor"
                type="text"
                name="name"
                autocomplete="off"
                class="layui-input"
              />
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">联系方式:</label>
            <div class="layui-input-inline">
              <input
                id="contact"
                type="tel"
                name="phone"
                autocomplete="off"
                class="layui-input"
                value="xxxxx"
              />
            </div>
          </div>
        </div>
      </form>
    </script>
    <script src="../../layuiadmin/modules/const_config.js"></script>
    <script src="../../layuiadmin/modules/jTools.js"></script>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script>
      layui
        .config({
          base: "../../layuiadmin/", //静态资源所在路径
        })
        .extend({
          index: "lib/index", //主入口模块
        })
        .use(["index", "contlist", "table"], function () {
          var table = layui.table,
            $ = layui.$,
            form = layui.form,
            uuid = layui.data("uuid").key,
            no = layui.data("no").key,
            type = layui.data("technicalType").key,
            fileid = "";
          $(
            '#LAY-system-side-menu dd[data-name="specialProtectionEnd"]',
            parent.document
          ).addClass("layui-this");
          permissionList();
          function permissionList() {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/SpecialProtection/createSpecialProtectionList",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({ uuid, no, type }),
              success: function (data) {
                if (data.type == "success") {
                  var data = data.data.reverse();
                  var html = "";
                  for (var i = 0; i < data.length; i++) {
                    fileid = data[i].no;
                    if (i == data.length - 1) {
                      html += `
                      <li class="time_horizontal_part" data-id="${data[i].pdfName}" data-fileid="${fileid}" data-name="${data[i].wordName}">
                          <b class="active"></b>
                          ${data[i].createTime}<br/>
                      </li>`;
                      $("#pdf").attr(
                        "src",
                        "../../layuiadmin/web/viewer.html?file=" +
                          data[i].pdfName +
                          ""
                      );
                    } else {
                      html += `
                      <li class="time_horizontal_part" data-id="${data[i].pdfName}" data-fileid="${fileid}" data-name="${data[i].wordName}">
                          <b></b>
                          ${data[i].createTime}<br/>
                      </li>`;
                    }
                  }
                  $(".time_horizontal").html(html);
                  $(".time_horizontal_part").on("click", function () {
                    var uuid = $(this).attr("data-id");
                    fileid = $(this).attr("data-fileid");
                    $(this).children("b").addClass("active");
                    $(this).siblings("li").children("b").removeClass("active");
                    $("#pdf").attr(
                      "src",
                      "../../layuiadmin/web/viewer.html?file=" + uuid
                    );
                  });
                  $(".downLoadWord").on("click", function () {
                    window.location.href = $(".active")
                      .parent()
                      .attr("data-name");
                  });
                  $(".time_horizontal").scrollLeft(
                    $(".time_horizontal")[0].scrollWidth
                  );
                } else {
                  layer.msg("专项保护方案列表为空", { icon: 6 });
                }
              },
            });
          }
          $(".deleteTechnical").on("click", function () {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/SpecialProtection/createdelect",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({ no: fileid }),
              success: function (data) {
                if ((data.type = "success")) {
                  layer.confirm("确认删除吗?", function (index) {
                    $(".active").parent().remove();
                    permissionList();
                    layer.msg(data.message, { icon: 6 });
                  });
                } else {
                  layer.msg(data.message, { icon: 5 });
                }
              },
            });
          });
          $(".backNextBtn").on("click", function () {
            // 专项保护方案-退回意见
            layer.open({
              type: 1,
              skin: "demo-class",
              area: ["50%", "40%"],
              shadeClose: true,
              content: $("#speProSchemeReturn").html(),
              title: ["退回意见"],
              btn: ["确定", "取消"],
              btnAlign: "c",
              success: function (layero, index) {
                $("#specialAuditor").val(layui.sessionData("userName").key);
              },
              yes: function (index, layero) {
                // 1、先获取专项保护方案在档案系统的编号
                $.ajax({
                  type: "post",
                  async: true, //异步执行
                  url: base_url + "/SpecialProtection/specialProtectionPlanId",
                  headers: {
                    Accept: "application/json; charset=utf-8",
                    Authorization: layui.sessionData("userToken").key,
                  },
                  contentType: "application/json; charset=UTF-8",
                  WdataType: "json",
                  data: JSON.stringify({
                    uuid: layui.data("uuid").key,
                  }),
                  success: function (data) {
                    if (data.code == 200) {
                      // 2、根据获取的档案系统文件ID调用报审的专项保护方案退回接口

                      // 档案系统编号
                      var fileSystemFile = data.data.fileSystemFile;
                      // 档案系统word文件名
                      var wordname = data.data.wordname;
                      // 申报类型
                      var type = data.data.type;
                      // 退回意见
                      var commentsTxt = $("#commentsTxt").val();
                      // 审批人
                      var auditor = $("#specialAuditor").val();
                      // 联系方式
                      var contact = $("#contact").val();

                      $.ajax({
                        type: "post",
                        async: true, //异步执行
                        url: "http://10.1.14.200/MMS/api/plotting/checkProjectFile",
                        headers: {
                          Accept: "application/json; charset=utf-8",
                        },
                        contentType: "application/json; charset=UTF-8",
                        WdataType: "json",
                        data: JSON.stringify({
                          no: layui.data("no").key,
                          fileId: fileSystemFile,
                          fileName: wordname,
                          fileType: "word",
                          opinion: commentsTxt,
                          personNumber: auditor,
                          contact: contact,
                          type: type,
                          uuid: layui.data("uuid").key,
                        }),
                        success: function (data) {
                          if (data.code == 200) {
                            // 3、报审数据传入成功，调用技审流程变更状态接口变更流程状态
                            $.ajax({
                              type: "post",
                              async: true, //异步执行
                              url:
                                base_url +
                                "/SpecialProtection/SpecialProtectionPass",
                              headers: {
                                Accept: "application/json; charset=utf-8",
                                Authorization:
                                  layui.sessionData("userToken").key,
                              },
                              contentType: "application/json; charset=UTF-8",
                              WdataType: "json",
                              data: JSON.stringify({
                                uuid: layui.data("uuid").key,
                                flow_status: "8",
                              }),
                              success: function (data) {
                                if (data.code == 200) {
                                  layer.msg(data.message, {
                                    time: 1000,
                                    icon: 6,
                                    end: function () {
                                      window.location.reload();
                                    },
                                  });
                                } else {
                                  layer.msg(data.message, { icon: 2 });
                                }
                              },
                            });
                          } else {
                            layer.msg(data.message, { icon: 2 });
                          }
                        },
                      });
                    } else {
                      layer.msg(data.message, { icon: 2 });
                    }
                  },
                });
              },
            });

            // $(".returnComments").show();
          });
          $(".returnComments .closeBtn").on("click", function () {
            $("#returnComments")[0].reset();
            $(".returnComments").hide();
          });
          $(".backPreviousPage").on("click", function () {
            $(this).attr("lay-href", "./pages/technicalReview.html");
          });
        });
    </script>
  </body>
</html>
